package com.firstsource.networking.ip.tracker.data.access;

import java.util.ArrayList;
import org.hibernate.Session;
import com.firstsource.networking.ip.tracker.data.HibernateUtil ;
import com.firstsource.networking.ip.tracker.data.entities.Location;

public class LocationDAO {

	private Session session  = null ;

	public LocationDAO() {
		session = HibernateUtil.currentSession() ;
	}

	public void saveOrUpdate(Location currLoc) {
		session.beginTransaction() ;
		session.saveOrUpdate(currLoc) ;
		session.getTransaction().commit() ;
	}

	@SuppressWarnings("unchecked")
	public ArrayList<Location> getLocationByName(String name) {
		
		session.beginTransaction() ;
		ArrayList<Location> retVal = (ArrayList)session.createQuery("From Location where name like :name").setString("name", "%"+name+"%").list() ;
		session.getTransaction().commit() ;
		
		return retVal ;
	}
}
